package com.spel.service.impl;

import com.spel.constant.UserPermissionConstant;
import com.spel.form.UserSearchForm;
import com.spel.validate.annotation.BaseAssert;
import com.spel.validate.annotation.BatchAssert;
import com.spel.validate.enums.AssertTypeEnum;
import com.spel.validate.enums.LogicalEnum;
import com.spel.validate.service.ValidateThrowsService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @title: UserServiceImpl
 * @Author xu-xiang
 * @Date: 2024/1/30 15:08
 * @description:
 */
@Service
//@HasPermissions(validatorBeanClass = AuthService.class, value = "isSuperAdmin()")  //表示只有管理员才能访问这个类里面的方法
public class UserService {

    @BatchAssert(value = {
            @BaseAssert(
                    assertType = AssertTypeEnum.PERMISSION_ASSERT,
                    validatorBeanClass = ValidateThrowsService.class,
                    value = "isSuperAdmin()"
            ),
            @BaseAssert(
                    assertType = AssertTypeEnum.PERMISSION_ASSERT,
                    validatorBeanClass = ValidateThrowsService.class,
                    value = "hasPermission('" + UserPermissionConstant.PERMISSION_USER_QUERY + "')"
            )
    }, Logical = LogicalEnum.AND)  // AND表示,必须是管理员, 并且有查询权限,两个条件同时满足,才能访问此接口
    public Object queryUser(UserSearchForm userSearchForm) {
        Map<String, Object> userMap = new HashMap<>();
        userMap.put("name", "张三");
        userMap.put("age", 13);
        return userMap;
    }
}
